<?php

namespace App\Http\Controllers\View\User;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Facades\Services\User\WeightService;
use App\Facades\Utils\ValidateParameter;

class WeightController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   
        return view('pages.user.health_info.weight.list',[
            'weights' => WeightService::getWeights()->toArray(),
            'hasRecord' => WeightService::todayHasCreate()
        ]);
    }

    public function update(Request $request){

        $rules = [
            'id' => 'required|exists:weights,id'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        return view('pages.user.health_info.weight.update',[
            'weight' => WeightService::getRecordById($data),
            'height' => WeightService::getHegithInSession()
        ]);
    }

    public function create(){
        return view('pages.user.health_info.weight.create',[
            'height' => WeightService::getHegithInSession()
        ]);
    }
}
